package com.umeng.analytics.pro;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.Locale;

public final class cc {
    public class a {
        private final int a;
        private File b;
        private FilenameFilter c;

        public a(Context arg2) {
            this(arg2, ".um");
        }

        public a(Context arg3, String arg4) {
            this.a = 10;
            this.c = new FilenameFilter() {
                @Override
                public boolean accept(File arg2, String arg3) {
                    return arg3.startsWith("um");
                }
            };
            this.b = new File(arg3.getFilesDir(), arg4);
            if (!this.b.exists() || !this.b.isDirectory()) {
                this.b.mkdir();
            }
        }

        public void a(b arg6) {
            int v0 = 0;
            File[] v2 = this.b.listFiles(this.c);
            if (v2 != null && v2.length >= 10) {
                Arrays.sort(((Object[]) v2));
                final int v3 = v2.length - 10;
                bz.b(new Runnable() {
                    @Override
                    public void run() {
                        if (v3 > 0) {
                            m.a(cc.j()).a(((long) v3), System.currentTimeMillis(), "__evp_file_of");
                        }
                    }
                });
                int v1;
                for (v1 = 0; v1 < v3; ++v1) {
                    v2[v1].delete();
                }
            }

            if (v2 != null && v2.length > 0) {
                arg6.a(this.b);
                int v1 = v2.length;
                while (v0 < v1) {
                    try {
                        if (!arg6.b(v2[v0])) {

                        } else {
                            v2[v0].delete();
                        }
                    } catch (Throwable v3_1) {
                        v2[v0].delete();
                    }
                    ++v0;
                }

                arg6.c(this.b);
            }
        }

        public void a(byte[] arg7) {
            if (arg7 != null && arg7.length != 0) {
                File v1 = new File(this.b, String.format(Locale.US, "um_cache_%d.env", Long.valueOf(System.currentTimeMillis())));
                try {
                    bw.a(v1, arg7);
                } catch (Exception v0) {
                }
            }
        }

        public boolean a() {
            File[] v0 = this.b.listFiles();
            boolean v0_1 = v0 == null || v0.length <= 0 ? false : true;
            return v0_1;
        }

        public void b() {
            File[] v1 = this.b.listFiles(this.c);
            if (v1 != null && v1.length > 0) {
                int v2 = v1.length;
                int v0;
                for (v0 = 0; v0 < v2; ++v0) {
                    v1[v0].delete();
                }
            }
        }

        public int c() {
            File[] v0 = this.b.listFiles(this.c);
            int v0_1 = v0 == null || v0.length <= 0 ? 0 : v0.length;
            return v0_1;
        }
    }

    public interface b {
        void a(File arg1);

        boolean b(File arg1);

        void c(File arg1);
    }

    private static cc a = null;
    private static Context b = null;
    private static String c = null;
    private a d;
    private static final String e = "mobclick_agent_user_";
    private static final String f = "mobclick_agent_header_";
    private static final String g = "mobclick_agent_cached_";

    static {
        cc.a = null;
    }

    public cc(Context arg2) {

        this.d = new a(arg2);
    }

    public final void a(int arg3) {
        SharedPreferences v0 = ba.a(cc.b);
        if (v0 != null) {
            v0.edit().putInt("vt", arg3).commit();
        }
    }

    public static cc a(Context arg2) {
        cc v0_1;
        Class v1 = cc.class;
        synchronized (v1) {
            cc.b = arg2.getApplicationContext();
            cc.c = arg2.getPackageName();
            if (cc.a == null) {
                cc.a = new cc(arg2);
            }

            v0_1 = cc.a;
        }
        return v0_1;
    }

    public final void a(String arg3) {
        SharedPreferences v0 = ba.a(cc.b);
        if (v0 != null) {
            v0.edit().putString("appkey", arg3).commit();
        }
    }

    public final void a(String arg3, String arg4) {
        if (!TextUtils.isEmpty(((CharSequence) arg3)) && !TextUtils.isEmpty(((CharSequence) arg4))) {
            SharedPreferences.Editor v0 = this.k().edit();
            v0.putString("au_p", arg3);
            v0.putString("au_u", arg4);
            v0.commit();
        }
    }

    public final String[] a() {
        String[] v0_1;
        String v0 = null;
        SharedPreferences v1 = this.k();
        String v2 = v1.getString("au_p", v0);
        String v1_1 = v1.getString("au_u", v0);
        if (v2 != null && v1_1 != null) {
            return new String[]{v2, v1_1};
        } else {
            return null;
        }
    }

    public final void a(byte[] arg2) {
        this.d.a(arg2);
    }

    public final void b() {
        this.k().edit().remove("au_p").remove("au_u").commit();
    }

    public final void b(String arg3) {
        SharedPreferences v0 = ba.a(cc.b);
        if (v0 != null) {
            v0.edit().putString("channel", arg3).commit();
        }
    }

    public final String c() {
        String v0 = null;
        SharedPreferences v1 = ba.a(cc.b);
        if (v1 != null) {
            v0 = v1.getString("appkey", v0);
        }

        return v0;
    }

    public final void c(String arg3) {
        SharedPreferences v0 = ba.a(cc.b);
        if (v0 != null) {
            v0.edit().putString("st", arg3).commit();
        }
    }

    public final String d() {
        String v0 = null;
        SharedPreferences v1 = ba.a(cc.b);
        if (v1 != null) {
            v0 = v1.getString("channel", v0);
        }

        return v0;
    }

    public final String e() {
        String v0 = null;
        SharedPreferences v1 = ba.a(cc.b);
        if (v1 != null) {
            v0 = v1.getString("st", v0);
        }

        return v0;
    }

    public final int f() {
        int v0 = 0;
        SharedPreferences v1 = ba.a(cc.b);
        if (v1 != null) {
            v0 = v1.getInt("vt", 0);
        }

        return v0;
    }

    public final void g() {
        cc.b.deleteFile(this.l());
        cc.b.deleteFile(this.m());
        w.a(cc.b).a(true, false);
        m.a(cc.b).b(new f() {
            public void a(Object arg2, boolean arg3) {
                arg2.equals("success");
            }
        });
    }

    public final boolean h() {
        return this.d.a();
    }

    public final a i() {
        return this.d;
    }

    static Context j() {
        return cc.b;
    }

    private SharedPreferences k() {
        return cc.b.getSharedPreferences("mobclick_agent_user_" + cc.c, 0);
    }

    private String l() {
        return "mobclick_agent_header_" + cc.c;
    }

    private String m() {
        String v0_2;
        SharedPreferences v0 = ba.a(cc.b);
        if (v0 != null) {
            int v0_1 = v0.getInt("versioncode", 0);
            int v1 = Integer.parseInt(bv.a(cc.b));
            if (v0_1 != 0 && v1 != v0_1) {
                v0_2 = "mobclick_agent_cached_" + cc.c + v0_1;
                return v0_2;
            }

            v0_2 = "mobclick_agent_cached_" + cc.c + bv.a(cc.b);
        } else {
            v0_2 = "mobclick_agent_cached_" + cc.c + bv.a(cc.b);
        }

        return v0_2;
    }
}

